var app = app || {};
app.friction = {};
app.friction.ballSize = 30;
app.friction.ballX = app.friction.ballSize / 2;
app.friction.ballY = app.friction.ballSize / 2;
app.friction.vx = 5;
app.friction.vy = 5;
app.friction.duration = 0.5;
app.friction.fps = 24;
app.friction.left = 0;
app.friction.right = 250;
app.friction.top = 0;
app.friction.bottom = 200;
app.friction.friction = 0.995;

(function($) {

	$(function() {
		var ball = $('#ball');
		var friction = app.friction;
		var move = setInterval(function() {
			
			friction.vx *= friction.friction;
			friction.vy *= friction.friction;

			friction.ballX += friction.vx;
			friction.ballY += friction.vy;

			if ((friction.ballX - (friction.ballSize / 2)) < friction.left) {
				friction.ballX = friction.left + friction.ballSize / 2;
				friction.vx *= -1;
			} else if ((friction.right - (friction.ballSize / 2)) < friction.ballX) {
				friction.ballX = friction.right - (friction.ballSize / 2);
				friction.vx *= -1;
			}

			if ((friction.ballY - (friction.ballSize / 2)) < friction.top) {
				friction.ballY = friction.top + friction.ballSize / 2;
				friction.vy *= -1;
			} else if ((friction.bottom - (friction.ballSize / 2)) < friction.ballY) {
				friction.ballY = friction.bottom - (friction.ballSize / 2);
				friction.vy *= -1;
			}

			ball.css('left', (friction.ballX - (friction.ballSize / 2)));
			ball.css('top', (friction.ballY - (friction.ballSize / 2)));

		}, (1000 / friction.fps));
	});
})(jQuery);